[🤖] Add ^ Postfix Operator for Suffix String Matching#8
Open
[🤖] Add ^ Postfix Operator for Suffix String Matching#8
^ Postfix Operator for Suffix String Matching#8Conversation
- Add prefix operator ^ to check if strings start with a given value - Implement PrefixSearchStrategy class for prefix matching logic - Update StringPredicate enum with .prefix case - Add two prefix operator overloads: one for String and one for StringPredicate - Update SearchStrategyMaker to handle .prefix cases - Add comprehensive test coverage for the prefix operator including: - Basic prefix matching - Empty string handling - Combination with && and || operators - Negated prefix checks - Complex predicate combinations - Update README.md with ^ operator documentation and examples
- Add postfix operator ^ for suffix checks (e.g., "text"^) - Create SuffixSearchStrategy class to handle suffix evaluation - Update SearchStrategyMaker to handle .suffix cases - Add StringPredicate.suffix case to represent suffix predicates - Update README.md with suffix operator documentation and examples - Add comprehensive test suite covering: - Basic suffix matching - Combined with AND/OR operators - Diacritic sensitivity - Complex predicates - Interaction with prefix operator This completes the suffix operator functionality alongside the existing prefix operator.
- Removed Code Climate test coverage workflow from .github/workflows/swift.yml - Removed Code Climate maintainability and test coverage badges from README.md - Replaced Code Climate test coverage step with standard Swift test command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces the postfix
^operator to the StringContainsOperators library, enabling suffix stringmatching functionality. This complements the existing prefix
^operator and extends the library's capabilitiesfor expressive string search patterns.
Motivation
The StringContainsOperators library already provides elegant prefix matching via
^"value". However, there was noequivalent for suffix matching, requiring developers to fall back to native Swift's
hasSuffix()method, whichbreaks the fluent, composable pattern established by the library.
Before:
After:
What Changed
New Files
Sources/StringContainsOperators/SearchStrategies/SuffixSearchStrategy.swiftString.hasSuffix()Modified Files
1.
Sources/StringContainsOperators/StringContainsOperators.swiftpostfix operator ^declaration.suffix(StringPredicateInputKind)case toStringPredicateenumpostfix func ^(value: String) -> StringPredicatepostfix func ^(predicate: StringPredicate) -> StringPredicate2.
Sources/StringContainsOperators/SearchStrategyMaker.swift.suffixcase to the switch statementSuffixSearchStrategyfor suffix predicates3.
Tests/StringContainsOperatorsTests/StringContainsOperatorsTests.swifttestSuffixOperator()- Basic functionalitytestSuffixOperatorWithEmptyString()- Edge casestestSuffixOperatorCombinedWithOr()- OR combinationstestSuffixOperatorCombinedWithAnd()- AND combinationstestSuffixOperatorWithDiacriticInsensitivity()- Sensitivity behaviortestSuffixOperatorInComplexPredicate()- Complex predicatestestSuffixOperatorWithCombinedOperators()- Multi-operator combinationstestPrefixAndSuffixOperatorsTogether()- Prefix + suffix together4.
README.mdImplementation Details
Architecture
The implementation follows the library's established Strategy Pattern:
Operator: "Victor"^
↓
StringPredicate.suffix(.string("Victor"))
↓
SearchStrategyMaker.make() → SuffixSearchStrategy
↓
SuffixSearchStrategy.evaluate(string:)
↓
String.hasSuffix("Victor")
↓
Bool result
Combined with Other Operators
Mixed Prefix and Suffix
Compatibility
Breaking Changes
None - This is a purely additive change.
Migration Guide
No migration needed. The existing API remains unchanged. Users can start using the new suffix operator
immediately.
Future Enhancements
Potential future improvements could include:
Notes for Reviewers
^) used for both prefix and postfix is intentional and follows Swift's operator overloadingconventions
Checklist
Related Issues: None (this is a new feature)
PR Type: Feature Addition
Impact: Low (additive, no breaking changes)
Risk: Low (well-tested, follows existing patterns)